OPTIONAL Stacks.f

Only Forth Definitions

{
 Cell stacks
}

: stack,   here ,  cells allot ;

: stack: ( n -- <name> )   create   stack, ;

\ : push ( x stack -- )   cell over +! @ ! ;

icode push
   0 [ebx] ecx mov  \ get pointer
   0 [ebp] eax mov  \ value
   cell # 0 [ebx] add  \ inc pointer
   eax 4 [ecx] mov  \ store value
   4 [EBP] EBX MOV  \ 2drop
   8 # EBP ADD
   ret end-code

\ : top ( stack -- x )  @ ;
aka @ top

: 0stack ( stack -- )   dup ! ;

: empty?   dup @ = ;


\ : discard   -cell swap +! ;

icode discard
   4 # 0 [ebx] sub
   pop(ebx)
   ret end-code

: pop ( stack -- x )
   [defined] check-stacks [if]  dup empty? abort" error: stack empty"  [then]
   dup top @
   swap discard ;

: clear-stack
   dup ! ;

: stack-count
   @+ over - cell / 1 + ;
